package com.ewanghuiju.app.presenter.pintuan;

import com.ewanghuiju.app.base.RxPresenter;
import com.ewanghuiju.app.base.contract.pintuan.PintuanDetailsContract;
import com.ewanghuiju.app.model.DataManager;
import com.ewanghuiju.app.model.bean.response.PintuanHeadListResponBean;
import com.ewanghuiju.app.model.bean.response.PintuanShopListResponBean;
import com.ewanghuiju.app.model.bean.response.RuleBean;
import com.ewanghuiju.app.model.bean.response.ShareResponBean;
import com.ewanghuiju.app.model.http.response.Optional;
import com.ewanghuiju.app.util.RxUtil;
import com.ewanghuiju.app.widget.CommonSubscriber;

import java.util.List;

import javax.inject.Inject;

/**
 * @author sj  qq:751943509
 * @class 拼团订单用户详情
 * @time 2020/2/16
 */
public class PintuanDetailsPresenter extends RxPresenter<PintuanDetailsContract.View> implements PintuanDetailsContract.Presenter {

    private DataManager mDataManager;
//    private int currentType = Constants.TYPE_ADDRESS_SELECTED;

    @Inject
    public PintuanDetailsPresenter(DataManager mDataManager) {
        this.mDataManager = mDataManager;
    }

    @Override
    public void getData(String order_id) {
    }

    /**
     * 获取用户头像信息
     *
     * @param group_id
     */
    @Override
    public void getPtigroupUserImage(String group_id) {
        addSubscribe(mDataManager.getPtigroupUserImage(group_id)
                .compose(RxUtil.rxSchedulerHelper())
                .compose(RxUtil.handleMyResultCannull())
                .subscribeWith(new CommonSubscriber<Optional<PintuanHeadListResponBean>>(mView) {
                    @Override
                    public void onNext(Optional<PintuanHeadListResponBean> optional) {
                        if (mView != null)
                            mView.showContent(optional.getIncludeNull());
                    }

                    @Override
                    public void onError(Throwable e) {
                        super.onError(e);
                        if (mView != null) {
                            mView.showContentError();
                        }
                    }
                })
        );
    }

    /**
     * 获取分享信息
     *
     * @param goodsid
     * @param groupid
     */
    @Override
    public void getPtiptGoodsShare(String goodsid, String groupid) {
        addSubscribe(mDataManager.ptiptGoodsShare(goodsid, groupid)
                .compose(RxUtil.rxSchedulerHelper())
                .compose(RxUtil.handleMyResultCannull())
                .subscribeWith(new CommonSubscriber<Optional<ShareResponBean>>(mView) {
                    @Override
                    public void onNext(Optional<ShareResponBean> optional) {
                        if (mView != null)
                            mView.showPtiptGoodsShare(optional.getIncludeNull());
                    }

                    @Override
                    public void onError(Throwable e) {
                        super.onError(e);
                    }
                })
        );
    }

    /**
     * 获取推荐团购
     *
     * @param page
     */
    @Override
    public void getHotShopList(int page) {
        addSubscribe(mDataManager.getPtihotGoodsList(page, "", "", "")
                        .compose(RxUtil.rxSchedulerHelper())
                        .compose(RxUtil.handleMyResultCannull())
                        .subscribeWith(new CommonSubscriber<Optional<List<PintuanShopListResponBean>>>(mView) {
                            @Override
                            public void onNext(Optional<List<PintuanShopListResponBean>> optional) {
                                if (mView != null)
                                    mView.showHotShopList(optional.getIncludeNull());
                            }

                            @Override
                            public void onError(Throwable e) {
                                super.onError(e);
//                                if (mView != null)
//                                    mView.showContentError();
                            }
                        })
        );
    }

    @Override
    public void getPtiguize(String type) {
        //获取规则
        addSubscribe(mDataManager.getPtiguize(type)
                .compose(RxUtil.rxSchedulerHelper())
                .compose(RxUtil.handleMyResultCannull())
                .subscribeWith(new CommonSubscriber<Optional<RuleBean>>(mView) {
                    @Override
                    public void onNext(Optional<RuleBean> optional) {
                        if (mView != null)
                            mView.showPtiguize(optional.getIncludeNull());
                    }

                    @Override
                    public void onError(Throwable e) {
                        super.onError(e);
                    }
                })
        );
    }

}
